package com.ycw.servlet.XiaoYeZi;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ycw.dao.FlatplayDao;
import com.ycw.dao.impl.FlatplayImpl;
import com.ycw.pojo.Flatplay;

/**
 * Servlet implementation class FlatplayGetByConditionServlet
 */
@WebServlet("/FlatplayGetByConditionServlet")
public class FlatplayGetByConditionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public FlatplayGetByConditionServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		FlatplayDao fDao = new FlatplayImpl();
		int begin = (Integer.parseInt(request.getParameter("pageIndex")) - 1) * 10;

		Flatplay flatplay = new Flatplay();
		flatplay.setFpstartdate(request.getParameter("fp_start_date"));
		flatplay.setFptopic(request.getParameter("fp_topic"));
		flatplay.setFpplace(request.getParameter("fp_place"));
		flatplay.setSum(begin);

		System.out.println("begin：" + flatplay.getSum());
		List<Flatplay> resMap = fDao.getFlatplayByCondition(flatplay);

		String resJSON = JSON.toJSONString(resMap);
		PrintWriter out = response.getWriter();
		out.write(resJSON);
		out.close();
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
